package com.fr.chart.shape3d;

import com.fr.chart.math.Projection;
import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.GridLayout;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class CylinderDemo extends JFrame
{
  private static final long serialVersionUID = -6582385979641442957L;
  CylinderComponent comp;
  JSpinner rotation_spinner;
  JSpinner elevation_spinner;
  JSpinner focus_spinner;

  public static void main(String[] paramArrayOfString)
  {
    new CylinderDemo();
  }

  public CylinderDemo()
  {
    init();
    setSize(800, 600);
    setDefaultCloseOperation(3);
    setTitle("Cylinder Demo");
    setVisible(true);
  }

  private void init()
  {
    JPanel localJPanel1 = (JPanel)getContentPane();
    localJPanel1.setLayout(new BorderLayout());
    this.comp = new CylinderComponent(this, new Cylinder(0.0D, 200.0D, 40.0D));
    localJPanel1.add(this.comp, "Center");
    JPanel localJPanel2 = new JPanel();
    localJPanel1.add(localJPanel2, "South");
    this.rotation_spinner = new JSpinner();
    this.rotation_spinner.setValue(new Integer(this.comp.getCylinder().getProjection().getRotation()));
    this.elevation_spinner = new JSpinner();
    this.elevation_spinner.setValue(new Integer(this.comp.getCylinder().getProjection().getElevation()));
    this.focus_spinner = new JSpinner();
    this.focus_spinner.setValue(new Integer(this.comp.getCylinder().getProjection().getFocus()));
    localJPanel2.setLayout(new GridLayout(3, 2));
    localJPanel2.add(new JLabel("水平转角:"));
    localJPanel2.add(this.rotation_spinner);
    localJPanel2.add(new JLabel("上下仰角:"));
    localJPanel2.add(this.elevation_spinner);
    localJPanel2.add(new JLabel("透视系数:"));
    localJPanel2.add(this.focus_spinner);
    this.rotation_spinner.addChangeListener(new ChangeListener(this)
    {
      private final CylinderDemo this$0;

      public void stateChanged()
      {
        int i = (int)((Number)this.this$0.rotation_spinner.getValue()).doubleValue();
        this.this$0.comp.setRotaion(i);
      }
    });
    this.elevation_spinner.addChangeListener(new ChangeListener(this)
    {
      private final CylinderDemo this$0;

      public void stateChanged()
      {
        int i = (int)((Number)this.this$0.elevation_spinner.getValue()).doubleValue();
        this.this$0.comp.setElevation(i);
      }
    });
    this.focus_spinner.addChangeListener(new ChangeListener(this)
    {
      private final CylinderDemo this$0;

      public void stateChanged()
      {
        int i = (int)((Number)this.this$0.focus_spinner.getValue()).doubleValue();
        this.this$0.comp.setFocus(i);
      }
    });
  }

  private class CylinderComponent extends JComponent
  {
    Cylinder cylinder;
    int x;
    private final CylinderDemo this$0;

    public CylinderComponent(, Cylinder paramCylinder)
    {
      this.this$0 = paramCylinderDemo;
      this.cylinder = null;
      this.x = 0;
      this.cylinder = paramCylinder;
      this.cylinder.getProjection().setMode(1);
    }

    public void paintComponent()
    {
      paramGraphics.translate(300, 100);
      this.cylinder.draw(paramGraphics);
    }

    public void play()
    {
      int i = 0;
      i += 10;
      int j = 0;
      while (true)
      {
        if (j >= 360);
        this.cylinder.getProjection().setRotation(j + i);
        this.this$0.rotation_spinner.setValue(new Integer(j + i));
        this.cylinder.getProjection().setElevation(j);
        this.this$0.elevation_spinner.setValue(new Integer(j));
        repaint();
        try
        {
          Thread.sleep(100L);
        }
        catch (Exception localException)
        {
        }
        j += 10;
      }
    }

    public void setRotaion()
    {
      this.cylinder.getProjection().setRotation(paramInt);
      repaint();
    }

    public void setElevation()
    {
      this.cylinder.getProjection().setElevation(paramInt);
      repaint();
    }

    public void setFocus()
    {
      this.cylinder.getProjection().setFocus(paramInt);
      repaint();
    }

    public Cylinder getCylinder()
    {
      return this.cylinder;
    }
  }
}